package com.example.demo.controller;

import com.example.demo.commons.Commons;
import com.example.demo.entity.User;
import com.example.demo.http.Result;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public Result<User> insertNewUser(@RequestBody User user){
        if(userService.insertNewUser(user)){
            return Result.createSuccesful(user);
        }else{
            return Result.createError(Commons.NET_INSERT_ERROR,Commons.NET_INSERT_ERROR_MSG);
        }
    }

}
